<!--
 * Copyright (c) 2013-Now http://jeesite.com All rights reserved.
 * No deletion without permission, or be held responsible to law.
 * @author PR
-->
<template>
  <BasicModal
    v-bind="$attrs"
    :title="title"
    :ctype="type"
    :okText="t('确认')"
    @register="registerModal"
    @ok="handleSubmit"
    :minHeight="300"
    :width="500"
    :showOkBtn="false"
    :showCancelBtn="false"
  >
    <div class="ml-4 mt-4">
      <a-textarea
        v-model:value="inputRef"
        :placeholder="`请扫描${placeholder}(鼠标聚焦到当前位置)`"
        style="height: 250px; width: 450px"
        @keyup.enter="showInfo"
        ref="ainput"
      />
      <a-row :gutter="[16, 16]" style="margin-top: 20px; height: 30px">
        <a-col :span="24">
          <div v-if="tips == '扫码成功' || tips == '数据校验通过！'">
            <p class="tips-success">{{ tips }}</p>
          </div>
          <div v-else>
            <p class="tips-error">{{ tips }}</p>
          </div>
        </a-col>
      </a-row>
      <a-row :gutter="[16, 16]" style="margin-top: 15px">
        <a-col :span="5" :offset="14">
          <a-button type="error" @click="clearText('1')">重新扫描</a-button>
        </a-col>
        <a-col :span="5">
          <a-button type="success" @click="endScan()">结束扫描</a-button>
        </a-col>
      </a-row>
    </div>
  </BasicModal>
  <!-- 编程 -->
  <BasicModal
    @register="registerSxSelect"
    :title="'数铣工艺选择'"
    width="60%"
    :showFooter="true"
    @ok="handleSxCheck"
  >
    <SxRouteSelect ref="routeDataRef" :data="routeData" @success="handleSuccess" />
  </BasicModal>
  <SxForm @register="registerSxForm" @success="handleSuccess" />

  <!-- 图纸关联工艺 -->
  <BasicModal
    @register="registerOrderRouteSelect"
    :title="'常规工艺选择'"
    width="60%"
    :showFooter="true"
    @ok="handleOrderRouteCheck"
  >
    <OrderRouteSelect ref="orderRouteRef" :data="orderRouteData" @success="handleSuccess" />
  </BasicModal>
  <OrderRouteForm @register="registerOrderRouteForm" @success="handleSuccess" />

  <!-- 流程完工登记 -->
  <ListSelect
    @success="handleSuccess"
    selectType="picFlowSelect"
    :selectList="selectListRef"
    :checkbox="true"
    :params="queryParams"
    @select="handleFlowSelect"
    ref="listSelectRef"
    v-show="false"
  />
  <OverForm @register="registerOver" @success="handleSuccess" />
  <!-- 检验登记 -->
  <CheckForm @register="registerCheckForm" @success="handleSuccess" />

  <!-- 批量检验登记 -->
  <BatchCheck @register="registerBatchCheck" @success="handleSuccess" />
  <!-- 批量完工 -->
  <BatchOver @register="registerBatchOver" @success="handleSuccess" />

  <!-- 发料 -->
  <wxOut
    @register="registerOpenOutDrawer"
    @success="handleSuccess"
    @successPrint="handleSuccess1"
  />

  <!-- 退料 -->
  <InputFormModel
    @register="registerImportModal"
    @success="handleSuccess"
    @successPrint="handleSuccess1"
  />

  <!-- 收料 -->
  <InputFlowWxInForm @register="registerDrawer" @success="handleSuccess" />

  <!-- 发货登记 -->
  <FormTabs @register="registerOpenFHDrawer" @success="handleSuccess" />
  <ListSelect
    @success="handleSuccess"
    selectType="fhSelect"
    :selectList="selectListRef"
    :checkbox="true"
    :params="queryParams"
    @select="handleFhSelect"
    ref="fhListSelectRef"
    v-show="false"
  />

  <ListSelect
    @success="handleSuccess"
    selectType="outSelect"
    :selectList="selectListRef"
    :checkbox="true"
    :params="queryParams"
    @select="handleOutSelect"
    ref="outListSelectRef"
    v-show="false"
  />

  <ListSelect
    @success="handleSuccess"
    selectType="picFlowSelect"
    :selectList="selectListRef"
    :checkbox="true"
    :params="queryParams"
    @select="handleFlowSelects"
    ref="listSelectRefs"
    v-show="false"
  />

  <!-- 图纸对应检验单选择 -->
  <ListSelect
    @success="handleSuccess"
    selectType="operCheckSelect"
    :selectList="selectListRef"
    :checkbox="false"
    :params="queryParams"
    @select="handleCheckSelects"
    ref="operCheckSelectRefs"
    v-show="false"
  />
  <PrintModal @register="registerPrintModal" />
</template>
<script lang="ts" setup>
  import { ref, nextTick } from 'vue';
  import { useI18n } from '/@/hooks/web/useI18n';
  import { useMessage } from '/@/hooks/web/useMessage';

  import { useModal } from '/@/components/Modal';
  import { useDrawer } from '/@/components/Drawer';
  import { BasicModal, useModalInner } from '/@/components/Modal';
  import { extdBillImportData } from '/@/api/extd/bill/extdBill';
  import globalSetting from '/@/enums/globalSetting';
  import SxRouteSelect from '/@/views/bas/route/list.vue';
  import SxForm from '/@/views/m8/order/flow/flow/sxForm.vue';
  import OrderRouteSelect from '/@/views/bas/route/list.vue';
  import OrderRouteForm from '/@/views/m8/order/pic/m8OrderRoute/form.vue';
  import OverForm from '/@/views/m8/order/flow/over/overForm.vue';
  import CheckForm from '/@/views/m8/order/flow/check/form.vue';
  import BatchCheck from '/@/views/m8/order/flow/check/batchCheck.vue';
  import BatchOver from '/@/views/m8/order/flow/over/batchOverForm.vue';
  import wxOut from '/@/views/m8/order/flow/wx/m8OrderFlowWxOut/form.vue';
  import InputFlowWxInForm from '/@/views//m8/order/flow/wx/m8OrderFlowWxIn/form.vue';
  import InputFormModel from '/@/views//m8/order/flow/wx/m8OrderFlowWxOut/formModel.vue';
  import FormTabs from '/@/views/m8/order/flow/fh/formTabs.vue';
  import { findCheckListByPicId } from '/@/api/m8/order/m8OperCheck';

  import { ListSelect } from '/@/components/ListSelect';
  import { BarCodeCheck } from '/@/api/m8/barcode/barcode';
  import PrintModal from '/@/components/print/printModal.vue';
  const [registerPrintModal, { openModal: openPrintModal }] = useModal();

  const emit = defineEmits(['success', 'register']);
  const { t } = useI18n('extd.bill.extdBill');
  const { showMessage, showMessageModal, createConfirm } = useMessage();

  let placeholder = ref<string>('');
  const fileList = ref([]);
  const enterCount = ref(0);
  let inputRef = ref<string>('');
  let ainput = ref<any>(null);
  // const url = data;
  let url = ref<any>(null);
  let title = ref<any>(null);
  let type = ref<any>(null);
  let queryParams = ref({});
  const selectListRef = ref<Recordable[]>([]);

  let queryData = {
    userCode: '',
    picId: '',
    funcType: '',
    venCode: '',
    cusCode: '',
  };

  let flowIds = ref<any>([]);

  let routeDataRef = ref();
  let routeData = ref<any>();
  //关联工艺参数
  let orderRouteRef = ref();
  let orderRouteData = ref<any>();

  let listSelectRef = ref<any>(null);
  let listSelectRefs = ref<any>(null);
  let fhListSelectRef = ref<any>(null);
  let outListSelectRef = ref<any>(null);
  let operCheckSelectRefs = ref<any>(null);

  let checkData = ref<any>({});

  // 提示信息
  let tips = ref<string>('');

  const [registerModal, { setModalProps, closeModal }] = useModalInner((data) => {
    type.value = data.type;
    if (type.value == '3') {
      placeholder.value = '工牌和供应商'; //外协收料,外协退料
    } else if (type.value == '2') {
      placeholder.value = '图纸、工牌和供应商'; //外协收料,外协退料
    } else if (type.value == '7') {
      placeholder.value = '图纸、工牌和客户'; //发货登记
    } else if (type.value == '8') {
      placeholder.value = '客户和工牌'; //退货登记
    } else if (type.value === '9') {
      placeholder.value = '图纸'; //关联工艺
    } else if (type.value === globalSetting.workScanEnum.FT) {
      placeholder.value = '图纸'; //复投
    } else {
      placeholder.value = '图纸和工牌'; //其他
    }
    flowIds.value = [];
    enterCount.value = 0;
    inputRef.value = '';
    tips.value = '';
    queryData = {
      userCode: '',
      picId: '',
      funcType: '',
      venCode: '',
      cusCode: '',
    };
    url.value = data.url;
    title.value = data.title;
    type.value = data.type;
    ainput.value.focus();
    // fileList.value = [];
  });

  // 编程
  const [registerSxSelect, { openModal: openSxSelect, closeModal: closeSxSelect }] = useModal();
  const [registerSxForm, { openDrawer: openDrawerSxForm }] = useDrawer();
  // 关联工艺
  const [
    registerOrderRouteSelect,
    { openModal: openOrderRouteSelect, closeModal: closeOrderRouteSelect },
  ] = useModal();
  const [registerOrderRouteForm, { openDrawer: openDrawerOrderRouteForm }] = useDrawer();

  // 完工
  const [registerOver, { openDrawer: openOverDrawer }] = useDrawer();
  // 检验
  const [registerCheckForm, { openDrawer: openDrawerCheckForm }] = useDrawer();
  // 批量检验
  const [registerBatchCheck, { openDrawer: openDrawerBatchCheck }] = useDrawer();
  // 批量完工
  const [registerBatchOver, { openDrawer: openDrawerBatchOver }] = useDrawer();
  // 发料
  const [registerOpenOutDrawer, { openDrawer: openDrawerOut }] = useDrawer();
  // 退料
  const [registerImportModal, { openDrawer: importModal }] = useDrawer();
  // 收料
  const [registerDrawer, { openDrawer: openDrawer }] = useDrawer();
  // 发货登记
  const [registerOpenFHDrawer, { openDrawer: openDrawerFH }] = useDrawer();

  const showInfo = async () => {
    let lines = inputRef.value.split(/[(\r\n)\r\n]+/);
    lines.forEach((item, index) => {
      // 删除空项
      if (item === '') {
        lines.splice(index, 1);
      }
    });
    enterCount.value++;
    // 校验
    if (
      (enterCount.value === 2 &&
        type.value != '1' &&
        type.value != '2' &&
        type.value != '7' &&
        type.value != '10' &&
        type.value != '11') ||
      (enterCount.value === 1 && (type.value == '9' || type.value == '12'))
    ) {
      ainput.value.blur();
      // 验证用户、图纸是否合法
      lines.forEach((item) => {
        if (item.startsWith('98-')) {
          queryData.userCode = item;
        } else if (item.startsWith('99-')) {
          queryData.picId = item;
        } else if (item.startsWith('96-')) {
          queryData.venCode = item;
        } else if (item.startsWith('95-')) {
          queryData.cusCode = item;
        }
      });

      if (type.value == '3') {
        if (!queryData.userCode) {
          tips.value = '用户条码不正确!';
          clearText('');
          return false;
        }
        if (!queryData.venCode) {
          tips.value = '供应商条码不正确!';
          clearText('');
          return false;
        }
      } else if (type.value == '8') {
        if (!queryData.cusCode) {
          tips.value = '客户条码不正确!';
          clearText('');
          return false;
        }
        if (!queryData.userCode) {
          tips.value = '用户条码不正确!';
          clearText('');
          return false;
        }
      } else if (type.value == '9') {
        if (!queryData.picId) {
          tips.value = '图纸条码不正确!';
          clearText('');
          return false;
        }
      } else if (type.value == globalSetting.workScanEnum.FT) {
        if (!queryData.picId) {
          tips.value = '图纸条码不正确!';
          clearText('');
          return false;
        }
      } else {
        if (!queryData.picId) {
          tips.value = '图纸条码不正确!';
          clearText('');
          return false;
        }
        if (!queryData.userCode) {
          tips.value = '用户条码不正确!';
          clearText('');
          return false;
        }
      }

      tips.value = '扫码成功';
      let params = {
        funcType: type.value,
        barUser: queryData.userCode,
        barPic: queryData.picId,
        cusCode: queryData.cusCode,
        venCode: queryData.venCode,
      };

      // 数据校验
      let data = await BarCodeCheck(params);
      checkData.value = data;
      if (data.result) {
        tips.value = data.message; // 验证通过 提示信息
        if (!data.errorMsg) {
          clearText('1');
          switch (type.value) {
            case globalSetting.workScanEnum.BC: // 编程
              handleRouterList(data);
              break;
            case globalSetting.workScanEnum.GLGY: // 关联工艺
              handleOrderRouterList(data);
              break;
            case globalSetting.workScanEnum.FT: // 复投
              handleOrderRouterList_FT(data);
              break;
            case globalSetting.workScanEnum.LCWGDJ: // 流程完工登记
              if (data.flowCount > 1) {
                let params = {
                  picId: data.orderPic.id,
                  userCode: data.user.userCode,
                  type: '1',
                };
                queryParams.value = params;
                await nextTick(); //
                listSelectRef.value.openSelectModal();
              } else {
                handleOverData(data);
              }
              break;
            // case globalSetting.workScanEnum.JYDJ: // 检验登记
            //   if (data.flowCount > 1) {
            //     let params = {
            //       picId: data.orderPic.id,
            //       userCode: data.user.userCode,
            //       type: '2',
            //     };
            //     queryParams.value = params;
            //     await nextTick(); //
            //     listSelectRef.value.openSelectModal();
            //   } else {
            //     openDrawerCheckForm(true, { flowId: data.orderPicFlow.id });
            //   }
            //   break;
            case globalSetting.workScanEnum.JYDJ: // 检验登记 选择检验单
              if (data.checkCount > 1) {
                let params = {
                  picId: data.orderPic.id,
                };
                queryParams.value = params;
                await nextTick(); //
                operCheckSelectRefs.value.openSelectModal();
              } else {
                openDrawerCheckForm(true, {
                  djNo: data.check.id,
                  'checkor.userCode': data.user.userCode,
                });
              }
              break;
            case globalSetting.workScanEnum.WXFL: // 发料
              if (data.flowCount > 1) {
                let params = {
                  picId: data.orderPic.id,
                  userCode: data.user.userCode,
                  type: '1',
                };
                queryParams.value = params;
                await nextTick(); //
                listSelectRef.value.openSelectModal();
              } else {
                openDrawerOut(true, { selIds: data.orderPicFlow.id, ope: data.orderPicFlow.ope });
              }
              break;
            case globalSetting.workScanEnum.WXSL: // 收料
              let params1 = {
                'wxOut.venCode': data.venCode,
                'wxOut.outStatus': '4',
                'wxOut.bred': '0',
              };
              queryParams.value = params1;
              await nextTick(); //
              outListSelectRef.value.openSelectModal();
              break;
            case globalSetting.workScanEnum.WXTL: // 退料
              let params2 = {
                'wxOut.venCode': data.venCode,
                'wxOut.outStatus': '4',
                'wxOut.bred': '0',
              };
              queryParams.value = params2;
              await nextTick(); //
              outListSelectRef.value.openSelectModal();
              break;

            case globalSetting.workScanEnum.FHDJ: // 发货登记
              if (data.flowCount > 1) {
                let params = {
                  picId: data.orderPic.id,
                  userCode: data.user.userCode,
                  type: '1',
                };
                queryParams.value = params;
                await nextTick(); //
                listSelectRef.value.openSelectModal();
              } else {
                openDrawerFH(true, {
                  selIds: data.orderPicFlow.id,
                  bred: '0',
                  'sender.userCode': data.user.userCode,
                  'sender.userName': data.user.userName,
                });
              }
              break;
            case globalSetting.workScanEnum.THDJ: // 退货登记
              if (data.fhRdsCount > 1) {
                let params = {
                  'djNo.cusCode': data.cusCode,
                  'djNo.userCode': data.user.userCode,
                };
                queryParams.value = params;
                await nextTick(); //
                fhListSelectRef.value.openSelectModal();
              } else {
                openDrawerFH(true, {
                  selIds: data.orderPicFlow.id,
                  bred: '1',
                  cusCode: data.cusCode,
                  'sender.userCode': data.user.userCode,
                  'sender.userName': data.user.userName,
                });
              }
              break;
            case globalSetting.workScanEnum.PLWG: // 批量完工
              break;
          }
        } else {
          clearText('');
        }
      }
    }
  };

  function onUploadProgress(progressEvent: ProgressEvent) {
    const complete = ((progressEvent.loaded / progressEvent.total) * 100) | 0;
    if (complete != 100) {
      // uploadInfo.value = t('正在导入，请稍后') + ' ' + complete + '%...';
    } else {
      // uploadInfo.value = '';
    }
  }

  // 清空内容
  function clearText(flag) {
    inputRef.value = '';
    enterCount.value = 0;
    ainput.value.focus();
    queryData.picId = '';
    queryData.userCode = '';
    queryData.venCode = '';
    queryData.cusCode = '';
    if (flag == 1) {
      tips.value = '';
    }
    // console.log(ainput);
  }

  // 结束扫描
  async function endScan() {
    let lines = inputRef.value.split(/[(\r\n)\r\n]+/);
    lines.forEach((item, index) => {
      // 删除空项
      if (item === '') {
        lines.splice(index, 1);
      }
    });
    ainput.value.blur();

    let picArr = lines.filter((item) => {
      return item.startsWith('99-');
    });
    let userArr = lines.filter((item) => {
      return item.startsWith('98-');
    });
    let cusCodeArr = lines.filter((item) => {
      return item.startsWith('95-');
    });
    let venCodeArr = lines.filter((item) => {
      return item.startsWith('96-');
    });

    let flag = true;
    if (type.value == '2') {
      lines.forEach((item) => {
        if (!item.startsWith('99-') && !item.startsWith('98-') && !item.startsWith('96-')) {
          flag = false;
        }
      });
      if (!flag) {
        tips.value = '条码格式不正确!';
        clearText('');
        return false;
      }
      if (userArr.length != 1) {
        tips.value = '必须有1个用户!';
        return false;
      }
      if (picArr.length < 1) {
        tips.value = '至少包含1张图纸!';
        return false;
      }
      if (venCodeArr.length != 1) {
        tips.value = '必须有1个供应商!';
        return false;
      }
    } else if (type.value == '7') {
      lines.forEach((item) => {
        if (!item.startsWith('99-') && !item.startsWith('98-') && !item.startsWith('95-')) {
          flag = false;
        }
      });
      if (!flag) {
        tips.value = '条码格式不正确!';
        clearText('');
        return false;
      }
      if (userArr.length > 1) {
        tips.value = '用户条码只能为1个!';
        return false;
      }
      if (userArr.length == 0) {
        tips.value = '用户条码为空!';
        // clearText('');
        return false;
      }
      if (picArr.length == 0) {
        tips.value = '图纸条码为空!';
        // clearText('');
        return false;
      }
      if (cusCodeArr.length == 0) {
        tips.value = '客户条码为空!';
        // clearText('');
        return false;
      }
    } else if (type.value == '1') {
      lines.forEach((item) => {
        if (!item.startsWith('99-') && !item.startsWith('98-')) {
          flag = false;
        }
      });
      if (!flag) {
        tips.value = '条码格式不正确!';
        clearText('');
        return false;
      }
      if (userArr.length > 1) {
        tips.value = '用户条码只能为1个!';
        clearText('');
        return false;
      }
      if (userArr.length == 0) {
        tips.value = '用户条码为空!';
        // clearText('');
        return false;
      }
      if (picArr.length == 0) {
        tips.value = '图纸条码为空!';
        // clearText('');
        return false;
      }
    } else if (type.value == '10') {
      lines.forEach((item) => {
        if (!item.startsWith('99-') && !item.startsWith('98-')) {
          flag = false;
        }
      });
      if (!flag) {
        tips.value = '条码格式不正确!';
        clearText('');
        return false;
      }
      if (userArr.length > 1) {
        tips.value = '用户条码只能为1个!';
        clearText('');
        return false;
      }
      if (userArr.length == 0) {
        tips.value = '用户条码为空!';
        // clearText('');
        return false;
      }
      if (picArr.length == 0) {
        tips.value = '图纸条码为空!';
        // clearText('');
        return false;
      }

      const res = await findCheckListByPicId({ checkor: userArr[0], picIds: picArr.join(',') });
      if (res.message == '查询成功') {
        openDrawerBatchCheck(true, res);
        tips.value = '';
      } else {
        tips.value = res.message;
      }
      return false;
    } else if (type.value == '11') {
      lines.forEach((item) => {
        if (!item.startsWith('99-') && !item.startsWith('98-')) {
          flag = false;
        }
      });
      if (!flag) {
        tips.value = '条码格式不正确!';
        clearText('');
        return false;
      }
      if (userArr.length > 1) {
        tips.value = '用户条码只能为1个!';
        clearText('');
        return false;
      }
      if (userArr.length == 0) {
        tips.value = '用户条码为空!';
        // clearText('');
        return false;
      }
      if (picArr.length == 0) {
        tips.value = '图纸条码为空!';
        // clearText('');
        return false;
      }
    } else {
      clearText('');
      tips.value = '请重新扫码!';
      return false;
    }

    tips.value = '扫码成功';
    let params = {
      funcType: type.value,
      barUser: userArr[0],
      barPic: picArr.join(','),
      cusCode: cusCodeArr[0],
      venCode: venCodeArr[0],
    };
    // 数据校验
    let data = await BarCodeCheck(params);
    checkData.value = data;
    if (data.result) {
      tips.value = data.message; // 验证通过 提示信息
      if (!data.errorMsg) {
        clearText('1');
        switch (type.value) {
          case globalSetting.workScanEnum.WXFL: // 发料
            let flag = false;
            data.flowList.forEach((item) => {
              if (item.flowCount > 1) {
                flag = true;
              }
            });
            if (!flag) {
              let arr = data.flowList.map((item) => {
                return item.orderFlow.id;
              });
              openDrawerOut(true, {
                selIds: arr.join(','),
                'outUser.userCode': data.user.userCode,
              });
            } else {
              data.flowList.forEach(async (item) => {
                if (item.flowCount > 1) {
                  let params = {
                    picId: item.orderPic.id,
                    userCode: item.user.userCode,
                    type: '1',
                  };
                  queryParams.value = params;
                  await nextTick(); //
                  listSelectRefs.value.openSelectModal();
                } else {
                  flowIds.value.push(item.orderFlow.id);
                }
              });
            }
            break;
          case globalSetting.workScanEnum.WXSL: // 外协收料
            openDrawer(true, {
              selIds: checkData.value.picIds,
              'receiver.userCode': checkData.value.user.userCode,
              venCode: checkData.value.venCode,
            });
            break;
          case globalSetting.workScanEnum.FHDJ: // 发货登记
            let arr = data.orderPicFlowList.map((item) => {
              return item.id;
            });
            openDrawerFH(true, {
              selIds: arr.join(','),
              bred: '0',
              'sender.userCode': data.user.userCode,
              'sender.userName': data.user.userName,
              cusCode: data.cusCode,
            });
            break;
          case globalSetting.workScanEnum.PLWG:
            console.log(data);
            openDrawerBatchOver(true, data);
            break;
        }
      } else {
        clearText('');
      }
    }
  }

  // 数铣工艺选择
  function handleRouterList(record) {
    if (record.orderPic.bsxset == '1') {
      openDrawerSxForm(true, { id: record.orderPic.id });
    } else {
      routeData.value = record;
      routeData.value.flag = '1';
      routeData.value.sxManCode = record.user.userCode;
      routeData.value.sxManName = record.user.userName;
      openSxSelect(true);
    }
  }
  // 常规工艺选择
  function handleOrderRouterList(record) {
    if (record.orderPic.bsetRoute == '1') {
      openDrawerOrderRouteForm(true, { id: record.orderPic.id });
    } else {
      let param = {
        flag: '0',
        order: {
          id: record.orderPic.order.id,
        },
        id: record.orderPic.id,
      };
      orderRouteData.value = param;
      openOrderRouteSelect(true);
    }
  }
  //复投
  function handleOrderRouterList_FT(record) {
    openDrawerOrderRouteForm(true, { id: record.orderPic.id });
  }
  function handleSxCheck() {
    routeDataRef.value.openRouteForm();
    setTimeout(closeSxSelect);
  }
  function handleOrderRouteCheck() {
    orderRouteData.value.flag = '0';
    orderRouteRef.value.openRouteForm();
    setTimeout(closeOrderRouteSelect);
  }

  // 流程完工登记
  async function handleOverData(record) {
    let obj = {
      orderFlow: {
        id: record.orderPicFlow.id,
      },
      manCodes: record.user.userCode,
      manNames: record.user.userName,
    };
    openOverDrawer(true, obj);
  }

  async function handleFlowSelect(values: Recordable[]) {
    if (values.length == 0) {
      showMessage(t('请选择一条图纸流程!'));
      return;
    }
    let params = {
      id: '',
      order: values[0].order,
      orderPic: values[0].orderPic,
      orderFlow: {
        id: values[0].id,
        ope: values[0].ope,
      },
      oper: values[0].oper,
    };

    let arr = values.map((item) => {
      return item.id;
    });

    if (globalSetting.workScanEnum.LCWGDJ === type.value) {
      openOverDrawer(true, {
        id: '',
        order: params.order,
        orderPic: params.orderPic,
        orderFlow: params.orderFlow,
        oper: params.oper,
        manCodes: checkData.value.user.userCode,
        manNames: checkData.value.user.userName,
      });
    }
    // if (globalSetting.workScanEnum.JYDJ === type.value) {
    //   openDrawerCheckForm(true, {
    //     flowId: params.orderFlow.id,
    //     'checkor.userCode': checkData.value.user.userCode,
    //     'checkor.userName': checkData.value.user.userName,
    //   });
    // }
    if (globalSetting.workScanEnum.WXFL === type.value) {
      openDrawerOut(true, { selIds: params.orderFlow.id, ope: params.orderFlow.ope });
    }
    // if (globalSetting.workScanEnum.WXSL === type.value) {
    //   openDrawer(true, { selIds: params.orderFlow.id });
    // }
    // if (globalSetting.workScanEnum.WXTL === type.value) {
    //   importModal(true, { selIds: params.orderFlow.id });
    // }

    if (globalSetting.workScanEnum.FHDJ === type.value) {
      openDrawerFH(true, {
        selIds: arr.join(','),
        bred: '0',
        'sender.userCode': checkData.value.user.userCode,
        'sender.userName': checkData.value.user.userName,
      });
    }

    selectListRef.value = []; // 清空选择的内容
  }
  async function handleFhSelect(values: Recordable[]) {
    if (values.length == 0) {
      showMessage(t('请选择一条发货流程!'));
      return;
    }
    let arr = values.map((item) => {
      return item.id;
    });
    let selIds = arr.join(',');

    if (globalSetting.workScanEnum.THDJ === type.value) {
      openDrawerFH(true, {
        selIds: selIds,
        bred: '1',
        cusCode: checkData.value.cusCode,
        'sender.userCode': checkData.value.user.userCode,
        'sender.userName': checkData.value.user.userName,
      });
    }
  }
  async function handleOutSelect(values: Recordable[]) {
    if (values.length == 0) {
      showMessage(t('请选择一条发料流程!'));
      return;
    }
    let arr = values.map((item) => {
      return item.id;
    });
    let selIds = arr.join(',');

    if (globalSetting.workScanEnum.WXSL === type.value) {
      openDrawer(true, {
        selIds: selIds,
        'receiver.userCode': checkData.value.user.userCode,
        venCode: checkData.value.venCode,
      });
    }
    if (globalSetting.workScanEnum.WXTL === type.value) {
      importModal(true, {
        selIds: selIds,
        'outUser.userCode': checkData.value.user.userCode,
        venCode: checkData.value.venCode,
      });
    }
  }

  async function handleFlowSelects(values: Recordable[]) {
    if (values.length == 0) {
      showMessage(t('请选择一条图纸流程!'));
      return;
    }
    values.forEach((item) => {
      flowIds.value.push(item.id);
    });

    if (globalSetting.workScanEnum.WXFL === type.value) {
      openDrawerOut(true, {
        selIds: flowIds.value.join(','),
        'outUser.userCode': checkData.value.user.userCode,
      });
    }
    selectListRef.value = []; // 清空选择的内容
  }

  async function handleCheckSelects(values: Recordable[]) {
    if (values.length == 0) {
      showMessage(t('请选择一条检验记录!'));
      return;
    }
    if (globalSetting.workScanEnum.JYDJ === type.value) {
      openDrawerCheckForm(true, {
        djNo: values[0].djNo,
        'checkor.userCode': checkData.value.user.userCode,
      });
    }
    selectListRef.value = []; // 清空选择的内容
  }

  async function handleSubmit() {
    try {
      if (fileList.value.length == 0) {
        showMessage(t('请选择要导入的数据文件'));
        return;
      }
      setModalProps({ confirmLoading: true });
      const params = {
        file: fileList.value[0],
      };
      const { data } = await extdBillImportData(params, onUploadProgress);
      showMessageModal({ content: data.message });
      setTimeout(closeModal);
      emit('success');
    } catch (error: any) {
      if (error && error.errorFields) {
        showMessage(t('您填写的信息有误，请根据提示修正。'));
      }
      console.log('error', error);
    } finally {
      setModalProps({ confirmLoading: false });
    }
  }

  // 保存成功回调
  function handleSuccess() {
    setTimeout(() => {
      ainput.value.focus();
    }, 500);
  }

  function handleSuccess1(e) {
    createConfirm({
      title: `保存审核已成功（${e}）`,
      content: `是否需要立即打印本条数据`,
      iconType: 'success', //info
      cancelText: '取消',
      okText: '确定',
      onOk: async () => {
        sucPrint(e);
      },
    });
  }
  // 保存审核后打印
  const sucPrint = (ids) => {
    let obj = {
      title: '委外明细打印',
      ids: ids,
      height: '0.7',
      width: '0.6',
      fileName: 'printWxOut',
    };
    openPrintModal(true, obj);
  };
</script>

<style scoped>
  .ant-btn-error {
    /* margin-right: 10px; */
    float: right;
  }
  .ant-input {
    background: url(/@/assets/icons/scan-icon/bg.png) 370px 170px no-repeat;
    z-index: auto;
  }

  .tips-success {
    color: green;
    font-size: 18px;
  }

  .tips-error {
    color: red;
    font-size: 18px;
  }
</style>
